//
//  HBQHomeButton.m
//  HelloBeeQuick
//
//  Created by LiYiLin on 16/8/20.
//  Copyright © 2016年 LiYiLin. All rights reserved.
//

#import "HBQHomeButton.h"
#import <SDWebImage/UIButton+WebCache.h>
#import "HBQHeaderModel.h"

#define KButtonW 40
#define KButtonWidth (KWIDTH / 4)

@implementation HBQHomeButton

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self == [super initWithFrame:frame]) {
        [self setup_Button];
    }
    return self;
}

/*  ============================================================  */

#pragma mark - 重写保存控件数据的iconmodel的set方法,为控件赋值
- (void)setIconModel:(HBQHomeIconsModel *)iconModel {
    
    _iconModel = iconModel;
    
    [self sd_setImageWithURL:[NSURL URLWithString:iconModel.img] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"v2_placeholder_square"]];

    if (iconModel.name) {
        [self setTitle:iconModel.name forState:UIControlStateNormal];
    }

}

/*  ============================================================  */

#pragma mark - 配置界面
- (void)setup_Button {
    
    self.imageView.contentMode = UIViewContentModeScaleAspectFit;
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.font = [UIFont systemFontOfSize:12];
    [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self setTitleColor:KTHEMES forState:UIControlStateSelected];
}

/*  ============================================================  */

- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.imageView.frame = CGRectMake(0, 3, KButtonWidth, KButtonW);
    self.titleLabel.frame = CGRectMake(0, KButtonW + 6, KButtonWidth, self.bounds.size.height - KButtonW);
}


@end
